package OnlineExam.administrator;

import javax.servlet.http.*;
import org.apache.struts.action.*;
import OnlineExam.*;
import OnlineExam.db.*;


/**
 *  Adds a Category and initializes the Category Attributes to their default values.
 */


public final class AddCategoryAction extends Action 
{
    
    /**
	 *   The execute() method is where you provide your business logic.
	 */

    public ActionForward execute(ActionMapping mapping,ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
	{
        Category f = (Category) form;

		addCategory (f);

       	return (mapping.findForward("success"));
	}

	/**
	 *  adds a new category and assigns an administrator to it.
	 */
	
	private void addCategory(Category cat)
	{
		cat.setTestLength(0);
		cat.setTimeLimit(0);
		cat.setQuestionGeneration(null);
		
		try
		{
			DBUtil.insert (cat);
		}
		catch (DBException e)
		{
			System.out.println("Exception.." + e);
		}
	}
}
